package graph.drawingshapes.tools
{
	import common.MathHelper;
	
	import flash.display.BitmapData;
	
	public class SprayDrawingTool extends SimpleDrawingTool
	{
		public static const NAME:String = "SprayDrawingTool"
		public override function get getName():String 
		{
			return NAME;
		}
		
		protected virtual function get pattern():BitmapData
		{
			var patternSize:Number = size;
			var result:BitmapData = new BitmapData(patternSize, patternSize, true, 0x00FFFFFF);
			for (var i:Number = 0; i < patternSize * patternSize / 3; ++i)
			{
				var xPos:Number = MathHelper.getRandom(0, patternSize-1);
				var yPos:Number = MathHelper.getRandom(0, patternSize-1);
				result.setPixel32(xPos, yPos, color);
			}
			return result;
		}
		
		public function SprayDrawingTool(size:Number=DefaultSize, color:uint=DefaultColor, alpha:Number=DefaultAlpha)
		{
			super(size, color, alpha);
		}
		
		protected override function initDrawing():void
		{
			this.graphics.beginBitmapFill(pattern);
		}
		
		protected override function draw():void
		{
			var halfSize:Number = size/2;
			this.graphics.drawCircle(0,0,halfSize);
		}
		
		protected override function endDrawing():void
		{
			this.graphics.endFill();
		}
		
	}
}